package com.kx.game.center.servlet;

import com.kx.game.center.global.GSServices;
import com.kx.game.center.local.response.LocalErrorResponseCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 首页
 */
@WebServlet(urlPatterns = "/")
public class WelcomeServlet extends HttpServlet {

    private static Logger logger = LoggerFactory.getLogger(WelcomeServlet.class);

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            GSServices.loadManager.redisState();
//            logger.info(System.currentTimeMillis() + "开始");
//            Thread.sleep(3000);
//            GameServerEntity gameServerEntity = new GameServerEntity();
//            gameServerEntity.setServerId("11");
//            gameServerEntity.setLoginNum(11);
//            gameServerEntity.setIp("11");
//            gameServerEntity.setPort("11");
//            gameServerEntity.setConnectIp("11");
//            gameServerEntity.setConnectPort("11");
//            gameServerEntity.setCreateNum(Integer.valueOf("11"));
//            gameServerEntity.setTime("11" + "");
//            gameServerEntity.setState("11");
//            gameServerEntity.setType("11");
//            DaoManager.gameServerDao.insert(gameServerEntity);
//            DaoManager.gameServerDao.delete(gameServerEntity);
//            logger.info(System.currentTimeMillis() + "结束");
            GSServices.localManager.sendMessage(response, true, null, "首页界面");
        } catch (Exception e) {
            e.printStackTrace();
            GSServices.localManager.sendMessage(response, false, LocalErrorResponseCode.SYSTEM_ERROR, "fail");
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

    public static void main(String[] args) throws Exception {
        System.out.println(1);
        Thread.sleep(10000);
        System.out.println(0);
    }
}
